


//TIP 要<b>运行</b>代码，请按 <shortcut actionId="Run"/> 或
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。

import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

interface Service {
    void serve();
}
public class Main {

    public static void main(String[] aaaa) {
        //TIP 当文本光标位于高亮显示的文本处时按 <shortcut actionId="ShowIntentionActions"/>
        // 查看 IntelliJ IDEA 建议如何修正。
        System.out.printf("Hello and welcome!");
        String first = "a";
        String second = "ab";
        System.out.println(oneEditAway(first, second));

    }
    public static boolean oneEditAway(String first, String second) {
        if(Math.abs(first.length() - second.length()) > 1){
            return false;
        }else if(first.length() == 0 || second.length() == 0){
            return true;
        }
        if(first.length() > second.length()){
            return flag(first, second);
        }else if(first.length() < second.length()){
            return flag(second, first);
        }else {
            int index = 0;
            for (int i = 0; i < first.length(); i++){
                if(first.charAt(i) != second.charAt(i)){
                    index++;
                }
            }
            if(index > 1){
                return false;
            }else {
                return true;
            }
        }
    }

    public static boolean flag(String first, String second){
        int index1 = 0, index2 = 0;
        while (index1 < first.length() && index2 < second.length() && Math.abs(index1 - index2) < 2){
            if(first.charAt(index1) != second.charAt(index2)){
                index1++;
            }else {
                index1++;
                index2++;
            }
        }
        if(first.length() == index1 && index2 == second.length()){
            return true;
        }else {
            return false;
        }
    }
}


